package com.yint.tree;

/**
 * 叶子结点接口
 * <p>
 * Created by 殷田 on 2018/5/3.
 */
public abstract class Leaf {
    private STATUS state = STATUS.UNINIT;

    public final boolean entry(Tree tree) {
        if (!onEntry(tree)) {
            return false;
        }
        return true;
    }

    protected abstract boolean onEntry(Tree tree);

    public final STATUS tick(Tree tree) {
        state = onTick(tree);
        return state;
    }

    protected abstract STATUS onTick(Tree tree);

    public final void leave(Tree tree) {
        STATUS temp = getState();
        setState(STATUS.UNINIT);
        onLeave(tree, temp);
    }

    protected abstract void onLeave(Tree tree, STATUS state);

    protected final STATUS getState() {
        return state;
    }

    protected final void setState(STATUS state) {
        this.state = state;
    }
}
